package com.xiaoy.page.header;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import com.xiaoy.page.PageSimple;

public class BarHeader {
	
	private static Map<String ,Object> vs = new HashMap<String, Object>();
	static {
		InputStream is = BarHeader.class.getResourceAsStream("/pagebar.properties");
		Properties props = new Properties();
		try {
			props.load(is);
			Iterator<Object> it = props.keySet().iterator();
			while (it.hasNext()){
				String key = (String)it.next();
				vs.put(key,props.getProperty(key));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public BarHeader () {}
	
	private PageSimple page;
	public BarHeader (PageSimple page) {
		this.page=page;
	}
	
	public String initBar () {
		
	}
	
	
	public String  getSimpleBar () {
		
		if(page.getTotalPages()==0) page.setPageNo(0);
		String str = "";
		str+="页次:"+page.getPageNo()+"/"+page.getTotalPages()+"页&nbsp;&nbsp;";
		str+="共"+page.getTotalCount()+"条记录&nbsp;&nbsp;";
		str += "<a href='"+page.getUrl()+"&pageBean.pageNo="+page.getFirst()+"&pageBean.pageSize="+page.getPageSize()+"'>首页</a>&nbsp;";
		str +=  "<a href='"+page.getUrl()+"&pageBean.pageNo="+page.getPrePage()+"&pageBean.pageSize="+page.getPageSize()+"'>上一页</a>&nbsp;";
		str +=  "<a href='"+page.getUrl()+"&pageBean.pageNo="+page.getNextPage()+"&pageBean.pageSize="+page.getPageSize()+"'>下一页</a>&nbsp;";
		str +=  "<a href='"+page.getUrl()+"&pageBean.pageNo="+page.getTotalPages()+"&pageBean.pageSize="+page.getPageSize()+"'>尾页</a>&nbsp;";
		return str;
	}
	
}
